home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 November / macformat-018.iso / Utility Spectacular / Developer / macgambit-20-compiler-src-p1 / Runtime (.c & .h) / ext_mac.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-26  |  26.1 KB  |  903 lines  |  [TEXT/KAHL]

  1. /* Macintosh specific extensions */
  2.  
  3. /* This file is intended to be used for the addition of Scheme procedures */
  4. /* to access machine specific features (such as Toolbox routines).        */
  5.  
  6. #include "os.h"
  7. #include "mem.h"
  8.  
  9. #include "os_mac.h"
  10.  
  11. #include "os_mac_Help.h"
  12.  
  13. /*---------------------------------------------------------------------------*/
  14.  
  15. void pascal_str( str, pstr ) /* utility to convert to Pascal string */
  16. SCM_obj str;
  17. Str255 pstr;
  18. { long i, len = SCM_length( str );
  19.   if (len > 255) len = 255; /* truncate if too long */
  20.   pstr[0] = len;
  21.   for (i=0; i<len; i++) pstr[i+1] = SCM_obj_to_str(str)[i];
  22. }
  23.  
  24. /*---------------------------------------------------------------------------*/
  25.  
  26.  
  27. SCM_obj mac_X23newwindow( bounds, title, visible, procid, behind, goaway ) /* simplified version of NewWindow */
  28. SCM_obj bounds, title, visible, procid, behind, goaway;
  29. { WindowPtr w;
  30.   Str255 ptitle;
  31.   pascal_str( title, ptitle );
  32.   w = NewWindow( NULL, SCM_obj_to_str(bounds), ptitle,
  33.                  (visible!=SCM_false), (int)SCM_obj_to_int(procid),
  34.                  (WindowPtr)SCM_obj_to_int(behind), (goaway!=SCM_false), 0L );
  35.   return (long)SCM_int_to_obj((long)w);
  36.   /* Note: The pointer to the window is returned as a fixnum.  This should */
  37.   /* be fine assuming the Mac returns a pointer with the upper 4 bits of   */
  38.   /* the pointer at 0.  This is a reasonnable assumtion but it might cause */
  39.   /* problems if the MacOS starts using high memory.                       */
  40. }
  41.  
  42. SCM_obj mac_X23getnewwindow( windowid, behind ) /* simplified version of GetNewWindow */
  43. SCM_obj windowid, behind;
  44. { WindowPtr w;
  45.   w = GetNewWindow( (int)SCM_obj_to_int(windowid), NULL, (WindowPtr)SCM_obj_to_int(behind) );
  46.   return (long)SCM_int_to_obj((long)w);
  47. }
  48.  
  49. SCM_obj mac_X23disposewindow( w )  /* window pointer is a fixnum */
  50. SCM_obj w;
  51. { DisposeWindow( (WindowPtr)SCM_obj_to_int(w) ); return (long)SCM_false; }
  52.  
  53. SCM_obj mac_X23setwtitle( w, title )
  54. SCM_obj w, title;
  55. { Str255 ptitle;
  56.   pascal_str( title, ptitle );
  57.   SetWTitle( (WindowPtr)SCM_obj_to_int(w), ptitle );
  58.   return (long)SCM_false;
  59. }
  60.  
  61. SCM_obj mac_X23selectwindow( w )
  62. SCM_obj w;
  63. { SelectWindow( (WindowPtr)SCM_obj_to_int(w) ); return (long)SCM_false; }
  64.  
  65. SCM_obj mac_X23hidewindow( w )
  66. SCM_obj w;
  67. { HideWindow( (WindowPtr)SCM_obj_to_int(w) ); return (long)SCM_false; }
  68.  
  69. SCM_obj mac_X23showwindow( w )
  70. SCM_obj w;
  71. { ShowWindow( (WindowPtr)SCM_obj_to_int(w) ); return (long)SCM_false; }
  72.  
  73. SCM_obj mac_X23frontwindow()
  74. { return (long)SCM_int_to_obj((long)FrontWindow()); }
  75.  
  76. SCM_obj mac_X23findwindow( p, w_cell ) /* w_cell is a cons cell to hold window pointer */
  77. SCM_obj p, w_cell;
  78. { Point pt = *(Point *)SCM_obj_to_str(p);
  79.   WindowPtr w;
  80.   int res = FindWindow( pt, &w );
  81.   *(SCM_obj *)(w_cell-SCM_type_PAIR+PAIR_CAR*sizeof(SCM_obj)) = (long)SCM_int_to_obj((long)w);
  82.   return (long)SCM_int_to_obj((long)res);
  83. }
  84.  
  85. SCM_obj mac_X23trackgoaway( w, p )
  86. SCM_obj w, p;
  87. { Point pt = *(Point *)SCM_obj_to_str(p);
  88.   if (TrackGoAway( (WindowPtr)SCM_obj_to_int(w), pt )) return (long)SCM_true; else return (long)SCM_false;
  89. }
  90.  
  91. SCM_obj mac_X23dragwindow( w, p, r )
  92. SCM_obj w, p, r;
  93. { Point pt = *(Point *)SCM_obj_to_str(p);
  94.   DragWindow( (WindowPtr)SCM_obj_to_int(w), pt, SCM_obj_to_str(r) );
  95.   return (long)SCM_false;
  96. }
  97.  
  98. SCM_obj mac_X23invalrect( port, r )
  99. SCM_obj port, r;
  100. { GrafPtr save; GetPort( &save ); SetPort( (GrafPtr)SCM_obj_to_int(port) );
  101.   InvalRect( SCM_obj_to_str(r) );
  102.   SetPort( save );
  103.   return (long)SCM_false;
  104. }
  105.  
  106. SCM_obj mac_X23beginupdate( w )
  107. SCM_obj w;
  108. { BeginUpdate( (WindowPtr)SCM_obj_to_int(w) ); return (long)SCM_false; }
  109.  
  110. SCM_obj mac_X23endupdate( w )
  111. SCM_obj w;
  112. { EndUpdate( (WindowPtr)SCM_obj_to_int(w) ); return (long)SCM_false; }
  113.  
  114. /*---------------------------------------------------------------------------*/
  115.  
  116. SCM_obj mac_X23openport( port )
  117. SCM_obj port;
  118. { GrafPtr save; GetPort( &save );
  119.   OpenPort( (GrafPtr)SCM_obj_to_int(port) );
  120.   SetPort( save );
  121.   return (long)SCM_false;
  122. }
  123.  
  124. SCM_obj mac_X23initport( port )
  125. SCM_obj port;
  126. { GrafPtr save; GetPort( &save );
  127.   InitPort( (GrafPtr)SCM_obj_to_int(port) );
  128.   SetPort( save );
  129.   return (long)SCM_false;
  130. }
  131.  
  132. SCM_obj mac_X23closeport( port )
  133. SCM_obj port;
  134. { ClosePort( (GrafPtr)SCM_obj_to_int(port) ); return (long)SCM_false; }
  135.  
  136. SCM_obj mac_X23setport( port )
  137. SCM_obj port;
  138. { SetPort( (GrafPtr)SCM_obj_to_int(port) ); return (long)SCM_false; }
  139.  
  140. SCM_obj mac_X23getport()
  141. { GrafPtr port; GetPort( &port ); return (long)SCM_int_to_obj((long)port); }
  142.  
  143. SCM_obj mac_X23setorigin( port, h, v )
  144. SCM_obj port, h, v;
  145. { GrafPtr save; GetPort( &save ); SetPort( (GrafPtr)SCM_obj_to_int(port) );
  146.   SetOrigin( (int)SCM_obj_to_int(h), (int)SCM_obj_to_int(v) );
  147.   SetPort( save );
  148.   return (long)SCM_false;
  149. }
  150.  
  151. SCM_obj mac_X23backpat( port, pat )
  152. SCM_obj port, pat;
  153. { GrafPtr save; GetPort( &save ); SetPort( (GrafPtr)SCM_obj_to_int(port) );
  154.   BackPat( SCM_obj_to_str(pat) );
  155.   SetPort( save );
  156.   return (long)SCM_false;
  157. }
  158.  
  159. SCM_obj mac_X23hidecursor()
  160. { HideCursor(); return (long)SCM_false; }
  161.  
  162. SCM_obj mac_X23showcursor()
  163. { ShowCursor(); return (long)SCM_false; }
  164.  
  165. SCM_obj mac_X23pensize( port, width, height )
  166. SCM_obj port, width, height;
  167. { GrafPtr save; GetPort( &save ); SetPort( (GrafPtr)SCM_obj_to_int(port) );
  168.   PenSize( (int)SCM_obj_to_int(width), (int)SCM_obj_to_int(height) );
  169.   SetPort( save );
  170.   return (long)SCM_false;
  171. }
  172.  
  173. SCM_obj mac_X23penmode( port, mode )
  174. SCM_obj port, mode;
  175. { GrafPtr save; GetPort( &save ); SetPort( (GrafPtr)SCM_obj_to_int(port) );
  176.   PenMode( (int)SCM_obj_to_int(mode) );
  177.   SetPort( save );
  178.   return (long)SCM_false;
  179. }
  180.  
  181. SCM_obj mac_X23penpat( port, pat )
  182. SCM_obj port, pat;
  183. { GrafPtr save; GetPort( &save ); SetPort( (GrafPtr)SCM_obj_to_int(port) );
  184.   PenPat( SCM_obj_to_str(pat) );
  185.   SetPort( save );
  186.   return (long)SCM_false;
  187. }
  188.  
  189. SCM_obj mac_X23pennormal( port )
  190. SCM_obj port;
  191. { GrafPtr save; GetPort( &save ); SetPort( (GrafPtr)SCM_obj_to_int(port) );
  192.   PenNormal();
  193.   SetPort( save );
  194.   return (long)SCM_false;
  195. }
  196.  
  197. SCM_obj mac_X23moveto( port, h, v )
  198. SCM_obj port, h, v;
  199. { GrafPtr save; GetPort( &save ); SetPort( (GrafPtr)SCM_obj_to_int(port) );
  200.   MoveTo( (int)SCM_obj_to_int(h), (int)SCM_obj_to_int(v) );
  201.   SetPort( save );
  202.   return (long)SCM_false;
  203. }
  204.  
  205. SCM_obj mac_X23move( port, dh, dv )
  206. SCM_obj port, dh, dv;
  207. { GrafPtr save; GetPort( &save ); SetPort( (GrafPtr)SCM_obj_to_int(port) );
  208.   Move( (int)SCM_obj_to_int(dh), (int)SCM_obj_to_int(dv) );
  209.   SetPort( save );
  210.   return (long)SCM_false;
  211. }
  212.  
  213. SCM_obj mac_X23lineto( port, h, v )
  214. SCM_obj port, h, v;
  215. { GrafPtr save; GetPort( &save ); SetPort( (GrafPtr)SCM_obj_to_int(port) );
  216.   LineTo( (int)SCM_obj_to_int(h), (int)SCM_obj_to_int(v) );
  217.   SetPort( save );
  218.   return (long)SCM_false;
  219. }
  220.  
  221. SCM_obj mac_X23line( port, dh, dv )
  222. SCM_obj port, dh, dv;
  223. { GrafPtr save; GetPort( &save ); SetPort( (GrafPtr)SCM_obj_to_int(port) );
  224.   Line( (int)SCM_obj_to_int(dh), (int)SCM_obj_to_int(dv) );
  225.   SetPort( save );
  226.   return (long)SCM_false;
  227. }
  228.  
  229. SCM_obj mac_X23textfont( port, font )
  230. SCM_obj port, font;
  231. { GrafPtr save; GetPort( &save ); SetPort( (GrafPtr)SCM_obj_to_int(port) );
  232.   TextFont( (int)SCM_obj_to_int(font) );
  233.   SetPort( save );
  234.   return (long)SCM_false;
  235. }
  236.  
  237. SCM_obj mac_X23textface( port, face )
  238. SCM_obj port, face;
  239. { GrafPtr save; GetPort( &save ); SetPort( (GrafPtr)SCM_obj_to_int(port) );
  240.   TextFace( (int)SCM_obj_to_int(face) );
  241.   SetPort( save );
  242.   return (long)SCM_false;
  243. }
  244.  
  245. SCM_obj mac_X23textmode( port, mode )
  246. SCM_obj port, mode;
  247. { GrafPtr save; GetPort( &save ); SetPort( (GrafPtr)SCM_obj_to_int(port) );
  248.   TextMode( (int)SCM_obj_to_int(mode) );
  249.   SetPort( save );
  250.   return (long)SCM_false;
  251. }
  252.  
  253. SCM_obj mac_X23textsize( port, size )
  254. SCM_obj port, size;
  255. { GrafPtr save; GetPort( &save ); SetPort( (GrafPtr)SCM_obj_to_int(port) );
  256.   TextSize( (int)SCM_obj_to_int(size) );
  257.   SetPort( save );
  258.   return (long)SCM_false;
  259. }
  260.  
  261. SCM_obj mac_X23spaceextra( port, extra )
  262. SCM_obj port, extra;
  263. { GrafPtr save; GetPort( &save ); SetPort( (GrafPtr)SCM_obj_to_int(port) );
  264.   SpaceExtra( (int)SCM_obj_to_int(extra) );
  265.   SetPort( save );
  266.   return (long)SCM_false;
  267. }
  268.  
  269. SCM_obj mac_X23drawchar( port, ch ) /* ch is a Scheme character (a fixnum will also do!) */
  270. SCM_obj port, ch;
  271. { GrafPtr save; GetPort( &save ); SetPort( (GrafPtr)SCM_obj_to_int(port) );
  272.   DrawChar( (char)SCM_obj_to_int(ch) );
  273.   SetPort( save );
  274.   return (long)SCM_false;
  275. }
  276.  
  277. SCM_obj mac_X23drawstring( port, s ) /* s is a Scheme string */
  278. SCM_obj port, s;
  279. { GrafPtr save; GetPort( &save ); SetPort( (GrafPtr)SCM_obj_to_int(port) );
  280.   DrawText( SCM_obj_to_str(s), 0, SCM_length(s) );
  281.   SetPort( save );
  282.   return (long)SCM_false;
  283. }
  284.  
  285. SCM_obj mac_X23drawtext( port, textBuf, firstByte, byteCount ) /* textBuf is a Scheme string */
  286. SCM_obj port, textBuf, firstByte, byteCount;
  287. { GrafPtr save; GetPort( &save ); SetPort( (GrafPtr)SCM_obj_to_int(port) );
  288.   DrawText( SCM_obj_to_str(textBuf), (int)SCM_obj_to_int(firstByte), (int)SCM_obj_to_int(byteCount) );
  289.   SetPort( save );
  290.   return (long)SCM_false;
  291. }
  292.  
  293. SCM_obj mac_X23charwidth( port, ch ) /* ch is a Scheme character (a fixnum will also do!) */
  294. SCM_obj port, ch;
  295. { long width;
  296.   GrafPtr save; GetPort( &save ); SetPort( (GrafPtr)SCM_obj_to_int(port) );
  297.   width = CharWidth( (char)SCM_obj_to_int(ch) );
  298.   SetPort( save );
  299.   return SCM_int_to_obj( width );
  300. }
  301.  
  302. SCM_obj mac_X23stringwidth( port, s ) /* s is a Scheme string */
  303. SCM_obj port, s;
  304. { long width;
  305.   GrafPtr save; GetPort( &save ); SetPort( (GrafPtr)SCM_obj_to_int(port) );
  306.   width = TextWidth( SCM_obj_to_str(s), 0, SCM_length(s) );
  307.   SetPort( save );
  308.   return SCM_int_to_obj( width );
  309. }
  310.  
  311. SCM_obj mac_X23textwidth( port, textBuf, firstByte, byteCount ) /* textBuf is a Scheme string */
  312. SCM_obj port, textBuf, firstByte, byteCount;
  313. { long width;
  314.   GrafPtr save; GetPort( &save ); SetPort( (GrafPtr)SCM_obj_to_int(port) );
  315.   width = TextWidth( SCM_obj_to_str(textBuf), (int)SCM_obj_to_int(firstByte), (int)SCM_obj_to_int(byteCount) );
  316.   SetPort( save );
  317.   return SCM_int_to_obj( width );
  318. }
  319.  
  320. SCM_obj mac_X23localtoglobal( port, pt )
  321. SCM_obj port, pt;
  322. { GrafPtr save; GetPort( &save ); SetPort( (GrafPtr)SCM_obj_to_int(port) );
  323.   LocalToGlobal( SCM_obj_to_str(pt) );
  324.   SetPort( save );
  325.   return (long)SCM_false;
  326. }
  327.  
  328. SCM_obj mac_X23globaltolocal( port, pt )
  329. SCM_obj port, pt;
  330. { GrafPtr save; GetPort( &save ); SetPort( (GrafPtr)SCM_obj_to_int(port) );
  331.   GlobalToLocal( SCM_obj_to_str(pt) );
  332.   SetPort( save );
  333.   return (long)SCM_false;
  334. }
  335.  
  336. SCM_obj mac_X23framerect( port, r )
  337. SCM_obj port, r;
  338. { GrafPtr save; GetPort( &save ); SetPort( (GrafPtr)SCM_obj_to_int(port) );
  339.   FrameRect( SCM_obj_to_str(r) );
  340.   SetPort( save );
  341.   return (long)SCM_false;
  342. }
  343.  
  344. SCM_obj mac_X23paintrect( port, r )
  345. SCM_obj port, r;
  346. { GrafPtr save; GetPort( &save ); SetPort( (GrafPtr)SCM_obj_to_int(port) );
  347.   PaintRect( SCM_obj_to_str(r) );
  348.   SetPort( save );
  349.   return (long)SCM_false;
  350. }
  351.  
  352. SCM_obj mac_X23eraserect( port, r )
  353. SCM_obj port, r;
  354. { GrafPtr save; GetPort( &save ); SetPort( (GrafPtr)SCM_obj_to_int(port) );
  355.   EraseRect( SCM_obj_to_str(r) );
  356.   SetPort( save );
  357.   return (long)SCM_false;
  358. }
  359.  
  360. SCM_obj mac_X23invertrect( port, r )
  361. SCM_obj port, r;
  362. { GrafPtr save; GetPort( &save ); SetPort( (GrafPtr)SCM_obj_to_int(port) );
  363.   InvertRect( SCM_obj_to_str(r) );
  364.   SetPort( save );
  365.   return (long)SCM_false;
  366. }
  367.  
  368. SCM_obj mac_X23fillrect( port, r, pat )
  369. SCM_obj port, r, pat;
  370. { GrafPtr save; GetPort( &save ); SetPort( (GrafPtr)SCM_obj_to_int(port) );
  371.   FillRect( SCM_obj_to_str(r), SCM_obj_to_str(pat) );
  372.   SetPort( save );
  373.   return (long)SCM_false;
  374. }
  375.  
  376. SCM_obj mac_X23frameroundrect( port, r, ovWd, ovHt )
  377. SCM_obj port, r, ovWd, ovHt;
  378. { GrafPtr save; GetPort( &save ); SetPort( (GrafPtr)SCM_obj_to_int(port) );
  379.   FrameRoundRect( SCM_obj_to_str(r), (int)SCM_obj_to_int(ovWd), (int)SCM_obj_to_int(ovHt) );
  380.   SetPort( save );
  381.   return (long)SCM_false;
  382. }
  383.  
  384. SCM_obj mac_X23paintroundrect( port, r, ovWd, ovHt )
  385. SCM_obj port, r, ovWd, ovHt;
  386. { GrafPtr save; GetPort( &save ); SetPort( (GrafPtr)SCM_obj_to_int(port) );
  387.   PaintRoundRect( SCM_obj_to_str(r), (int)SCM_obj_to_int(ovWd), (int)SCM_obj_to_int(ovHt) );
  388.   SetPort( save );
  389.   return (long)SCM_false;
  390. }
  391.  
  392. SCM_obj mac_X23eraseroundrect( port, r, ovWd, ovHt )
  393. SCM_obj port, r, ovWd, ovHt;
  394. { GrafPtr save; GetPort( &save ); SetPort( (GrafPtr)SCM_obj_to_int(port) );
  395.   EraseRoundRect( SCM_obj_to_str(r), (int)SCM_obj_to_int(ovWd), (int)SCM_obj_to_int(ovHt) );
  396.   SetPort( save );
  397.   return (long)SCM_false;
  398. }
  399.  
  400. SCM_obj mac_X23invertroundrect( port, r, ovWd, ovHt )
  401. SCM_obj port, r, ovWd, ovHt;
  402. { GrafPtr save; GetPort( &save ); SetPort( (GrafPtr)SCM_obj_to_int(port) );
  403.   InvertRoundRect( SCM_obj_to_str(r), (int)SCM_obj_to_int(ovWd), (int)SCM_obj_to_int(ovHt) );
  404.   SetPort( save );
  405.   return (long)SCM_false;
  406. }
  407.  
  408. SCM_obj mac_X23fillroundrect( port, r, ovWd, ovHt, pat )
  409. SCM_obj port, r, ovWd, ovHt, pat;
  410. { GrafPtr save; GetPort( &save ); SetPort( (GrafPtr)SCM_obj_to_int(port) );
  411.   FillRoundRect( SCM_obj_to_str(r), (int)SCM_obj_to_int(ovWd), (int)SCM_obj_to_int(ovHt), SCM_obj_to_str(pat) );
  412.   SetPort( save );
  413.   return (long)SCM_false;
  414. }
  415.  
  416. SCM_obj mac_X23frameoval( port, r )
  417. SCM_obj port, r;
  418. { GrafPtr save; GetPort( &save ); SetPort( (GrafPtr)SCM_obj_to_int(port) );
  419.   FrameOval( SCM_obj_to_str(r) );
  420.   SetPort( save );
  421.   return (long)SCM_false;
  422. }
  423.  
  424. SCM_obj mac_X23paintoval( port, r )
  425. SCM_obj port, r;
  426. { GrafPtr save; GetPort( &save ); SetPort( (GrafPtr)SCM_obj_to_int(port) );
  427.   PaintOval( SCM_obj_to_str(r) );
  428.   SetPort( save );
  429.   return (long)SCM_false;
  430. }
  431.  
  432. SCM_obj mac_X23eraseoval( port, r )
  433. SCM_obj port, r;
  434. { GrafPtr save; GetPort( &save ); SetPort( (GrafPtr)SCM_obj_to_int(port) );
  435.   EraseOval( SCM_obj_to_str(r) );
  436.   SetPort( save );
  437.   return (long)SCM_false;
  438. }
  439.  
  440. SCM_obj mac_X23invertoval( port, r )
  441. SCM_obj port, r;
  442. { GrafPtr save; GetPort( &save ); SetPort( (GrafPtr)SCM_obj_to_int(port) );
  443.   InvertOval( SCM_obj_to_str(r) );
  444.   SetPort( save );
  445.   return (long)SCM_false;
  446. }
  447.  
  448. SCM_obj mac_X23filloval( port, r, pat )
  449. SCM_obj port, r, pat;
  450. { GrafPtr save; GetPort( &save ); SetPort( (GrafPtr)SCM_obj_to_int(port) );
  451.   FillOval( SCM_obj_to_str(r), SCM_obj_to_str(pat) );
  452.   SetPort( save );
  453.   return (long)SCM_false;
  454. }
  455.  
  456. SCM_obj mac_X23framearc( port, r, startAngle, arcAngle )
  457. SCM_obj port, r, startAngle, arcAngle;
  458. { GrafPtr save; GetPort( &save ); SetPort( (GrafPtr)SCM_obj_to_int(port) );
  459.   FrameArc( SCM_obj_to_str(r),(int)SCM_obj_to_int(startAngle), (int)SCM_obj_to_int(arcAngle) );
  460.   SetPort( save );
  461.   return (long)SCM_false;
  462. }
  463.  
  464. SCM_obj mac_X23paintarc( port, r, startAngle, arcAngle )
  465. SCM_obj port, r, startAngle, arcAngle;
  466. { GrafPtr save; GetPort( &save ); SetPort( (GrafPtr)SCM_obj_to_int(port) );
  467.   PaintArc( SCM_obj_to_str(r),(int)SCM_obj_to_int(startAngle), (int)SCM_obj_to_int(arcAngle) );
  468.   SetPort( save );
  469.   return (long)SCM_false;
  470. }
  471.  
  472. SCM_obj mac_X23erasearc( port, r, startAngle, arcAngle )
  473. SCM_obj port, r, startAngle, arcAngle;
  474. { GrafPtr save; GetPort( &save ); SetPort( (GrafPtr)SCM_obj_to_int(port) );
  475.   EraseArc( SCM_obj_to_str(r),(int)SCM_obj_to_int(startAngle), (int)SCM_obj_to_int(arcAngle) );
  476.   SetPort( save );
  477.   return (long)SCM_false;
  478. }
  479.  
  480. SCM_obj mac_X23invertarc( port, r, startAngle, arcAngle )
  481. SCM_obj port, r, startAngle, arcAngle;
  482. { GrafPtr save; GetPort( &save ); SetPort( (GrafPtr)SCM_obj_to_int(port) );
  483.   InvertArc( SCM_obj_to_str(r),(int)SCM_obj_to_int(startAngle), (int)SCM_obj_to_int(arcAngle) );
  484.   SetPort( save );
  485.   return (long)SCM_false;
  486. }
  487.  
  488. SCM_obj mac_X23fillarc( port, r, startAngle, arcAngle, pat )
  489. SCM_obj port, r, startAngle, arcAngle, pat;
  490. { GrafPtr save; GetPort( &save ); SetPort( (GrafPtr)SCM_obj_to_int(port) );
  491.   FillArc( SCM_obj_to_str(r),(int)SCM_obj_to_int(startAngle), (int)SCM_obj_to_int(arcAngle), SCM_obj_to_str(pat) );
  492.   SetPort( save );
  493.   return (long)SCM_false;
  494. }
  495.  
  496. /*---------------------------------------------------------------------------*/
  497.  
  498. /* menus */
  499.  
  500. SCM_obj mac_X23newmenu( menuid, str )
  501. SCM_obj menuid, str;
  502. { MenuHandle mh;
  503.   Str255 pstr;
  504.   pascal_str( str, pstr );
  505.   mh = NewMenu( (int)SCM_obj_to_int(menuid), pstr );
  506.   return (long)SCM_int_to_obj((long)mh);
  507. }
  508.  
  509. SCM_obj mac_X23getmenu( resourceid )
  510. SCM_obj resourceid;
  511. { MenuHandle mh;
  512.   mh = GetMenu( (int)SCM_obj_to_int(resourceid) );
  513.   return (long)SCM_int_to_obj((long)mh);
  514. }
  515.  
  516. SCM_obj mac_X23disposemenu( themenu )
  517. SCM_obj themenu;
  518. { DisposeMenu( (MenuHandle)SCM_obj_to_int(themenu) );
  519.   return (long)SCM_false;
  520. }
  521.  
  522. SCM_obj mac_X23appendmenu( themenu, str )
  523. SCM_obj themenu, str;
  524. { Str255 pstr;
  525.   pascal_str( str, pstr );
  526.   AppendMenu( (MenuHandle)SCM_obj_to_int(themenu), pstr );
  527.   return (long)SCM_false;
  528. }
  529.  
  530. SCM_obj mac_X23addresmenu( themenu, thetype )
  531. SCM_obj themenu, thetype;
  532. { AddResMenu( (MenuHandle)SCM_obj_to_int(themenu), *SCM_obj_to_vect(thetype) );
  533.   return (long)SCM_false;
  534. }
  535.  
  536. SCM_obj mac_X23insertresmenu( themenu, thetype, afteritem )
  537. SCM_obj themenu, thetype, afteritem;
  538. { InsertResMenu( (MenuHandle)SCM_obj_to_int(themenu), *SCM_obj_to_vect(thetype), (int)SCM_obj_to_int(afteritem) );
  539.   return (long)SCM_false;
  540. }
  541.  
  542. SCM_obj mac_X23insertmenu( themenu, beforeid )
  543. SCM_obj themenu, beforeid;
  544. { InsertMenu( (MenuHandle)SCM_obj_to_int(themenu), (int)SCM_obj_to_int(beforeid) );
  545.   return (long)SCM_false;
  546. }
  547.  
  548. SCM_obj mac_X23drawmenubar()
  549. { DrawMenuBar();
  550.   return (long)SCM_false;
  551. }
  552.  
  553. SCM_obj mac_X23deletemenu( menuid )
  554. SCM_obj menuid;
  555. { DeleteMenu( (int)SCM_obj_to_int(menuid) );
  556.   return (long)SCM_false;
  557. }
  558.  
  559. SCM_obj mac_X23clearmenubar()
  560. { ClearMenuBar();
  561.   return (long)SCM_false;
  562. }
  563.  
  564. SCM_obj mac_X23getnewmbar( menubarid )
  565. SCM_obj menubarid;
  566. { Handle h;
  567.   h = GetNewMBar( (int)SCM_obj_to_int(menubarid) );
  568.   return (long)SCM_int_to_obj((long)h);
  569. }
  570.  
  571. SCM_obj mac_X23getmenubar()
  572. { Handle h;
  573.   h = GetMenuBar();
  574.   return (long)SCM_int_to_obj((long)h);
  575. }
  576.  
  577. SCM_obj mac_X23setmenubar( menulist )
  578. SCM_obj menulist;
  579. { SetMenuBar( (Handle)SCM_obj_to_int(menulist) );
  580.   return (long)SCM_false;
  581. }
  582.  
  583. SCM_obj mac_X23menuselect( p )
  584. SCM_obj p;
  585. { Point startpt = *(Point *)SCM_obj_to_str(p);
  586.   long res = MenuSelect( startpt );
  587.   return (long)SCM_int_to_obj(res);
  588. }
  589.  
  590. SCM_obj mac_X23menukey( ch )
  591. SCM_obj ch;
  592. { long res = MenuKey( (char)SCM_obj_to_int(ch) );
  593.   return (long)SCM_int_to_obj(res);
  594. }
  595.  
  596. SCM_obj mac_X23hilitemenu( menuid )
  597. SCM_obj menuid;
  598. { HiliteMenu( (int)SCM_obj_to_int(menuid) );
  599.   return (long)SCM_false;
  600. }
  601.  
  602. SCM_obj mac_X23disableitem( themenu, item )
  603. SCM_obj themenu, item;
  604. { DisableItem( (MenuHandle)SCM_obj_to_int(themenu), (int)SCM_obj_to_int(item) );
  605.   return (long)SCM_false;
  606. }
  607.  
  608. SCM_obj mac_X23enableitem( themenu, item )
  609. SCM_obj themenu, item;
  610. { EnableItem( (MenuHandle)SCM_obj_to_int(themenu), (int)SCM_obj_to_int(item) );
  611.   return (long)SCM_false;
  612. }
  613.  
  614. SCM_obj mac_X23getmhandle( menuid )
  615. SCM_obj menuid;
  616. { MenuHandle mh;
  617.   mh = GetMHandle( (int)SCM_obj_to_int(menuid) );
  618.   return (long)SCM_int_to_obj((long)mh);
  619. }
  620.  
  621. /*---------------------------------------------------------------------------*/
  622.  
  623. /* stdfile */
  624.  
  625. #if THINK_C < 5
  626. #include <StdFilePkg.h>
  627. #endif
  628.  
  629. extern int getfullpathfromcurrentvolume( /* fName, Path, MaxLength, warn */ );
  630. extern int get_file( /* prompt, nbtypes, ftypes, path, maxlength */ );
  631. extern int put_file( /* prompt, deflt, path, maxlength */ );
  632.  
  633. SCM_obj mac_X23sfgetfile( s, prompt, ftypes ) /* s is a Scheme string which is overwritten */
  634. SCM_obj s, prompt, ftypes;
  635. {
  636.   int nbtypes = SCM_length(ftypes) / sizeof(long);
  637.   int maxlength = SCM_length(s);
  638.   char *p = SCM_obj_to_str(prompt);
  639.   long len = SCM_length(prompt);
  640.   Str255 pprompt;
  641.  
  642.   if (len >= 256) return (long)SCM_false;
  643.   pprompt[0] = len;
  644.   while (len > 0) { len--; pprompt[len+1] = p[len]; }
  645.  
  646.   p = SCM_obj_to_str(s);
  647.   if (get_file( pprompt, nbtypes, SCM_obj_to_str(ftypes), p, maxlength ))
  648.   {
  649.     len = 0;
  650.     while (p[len] != '\0') len++;
  651.     *(long *)(s - SCM_type_SUBTYPED) = SCM_make_header( len, SCM_subtype_STRING );
  652.     return s;
  653.   }
  654.   else
  655.     return (long)SCM_false;
  656. }
  657.  
  658. SCM_obj mac_X23sfputfile( s, prompt, dflt ) /* s is a Scheme string which is overwritten */
  659. SCM_obj s, prompt, dflt;
  660. {
  661.   int maxlength = SCM_length(s);
  662.   char *p = SCM_obj_to_str(prompt);
  663.   long len = SCM_length(prompt);
  664.   Str255 pprompt, pdflt;
  665.  
  666.   if (len >= 256) return (long)SCM_false;
  667.   pprompt[0] = len;
  668.   while (len > 0) { len--; pprompt[len+1] = p[len]; }
  669.  
  670.   p = SCM_obj_to_str(dflt);
  671.   len = SCM_length(dflt);
  672.   if (len >= 256) return (long)SCM_false;
  673.   pdflt[0] = len;
  674.   while (len > 0) { len--; pdflt[len+1] = p[len]; }
  675.  
  676.   p = SCM_obj_to_str(s);
  677.   if (put_file( pprompt, pdflt, p, maxlength ))
  678.   {
  679.     len = 0;
  680.     while (p[len] != '\0') len++;
  681.     *(long *)(s - SCM_type_SUBTYPED) = SCM_make_header( len, SCM_subtype_STRING );
  682.     return s;
  683.   }
  684.   else
  685.     return (long)SCM_false;
  686. }
  687.  
  688. /*---------------------------------------------------------------------------*/
  689.  
  690. SCM_obj mac_X23getmouse( pt )
  691. SCM_obj pt;
  692. { GetMouse( SCM_obj_to_str(pt) ); return (long)SCM_false; }
  693.  
  694. SCM_obj mac_X23button()
  695. { if (Button()) return (long)SCM_true; else return (long)SCM_false; }
  696.  
  697. SCM_obj mac_X23tickcount()
  698. { return SCM_int_to_obj( TickCount() ); }
  699.  
  700. SCM_obj mac_X23delay( numTicks )
  701. SCM_obj numTicks;
  702. { long finalTicks;
  703.   Delay( (long)SCM_obj_to_int(numTicks), &finalTicks );
  704.   return SCM_int_to_obj( finalTicks );
  705. }
  706.  
  707. SCM_obj mac_X23sysbeep( duration )
  708. SCM_obj duration;
  709. { SysBeep( (int)SCM_obj_to_int(duration) ); return (long)SCM_false; }
  710.  
  711. SCM_obj mac_X23seteventmask( theMask )
  712. SCM_obj theMask;
  713. { SetEventMask( (int)SCM_obj_to_int(theMask) ); return (long)SCM_false; }
  714.  
  715. SCM_obj mac_X23peek8( ptr )
  716. SCM_obj ptr;
  717. { return SCM_int_to_obj( (long)*((unsigned char *)SCM_obj_to_int(ptr)) ); }
  718.  
  719. SCM_obj mac_X23poke8( ptr, val )
  720. SCM_obj ptr, val;
  721. { *((unsigned char *)SCM_obj_to_int(ptr)) = (unsigned char)SCM_obj_to_int(val);
  722.   return (long)SCM_false;
  723. }
  724.  
  725. SCM_obj mac_X23peek16( ptr )
  726. SCM_obj ptr;
  727. { return SCM_int_to_obj( (long)*((short *)SCM_obj_to_int(ptr)) ); }
  728.  
  729. SCM_obj mac_X23poke16( ptr, val )
  730. SCM_obj ptr, val;
  731. { *((short *)SCM_obj_to_int(ptr)) = (short)SCM_obj_to_int(val);
  732.   return (long)SCM_false;
  733. }
  734.  
  735. SCM_obj mac_X23peek32( ptr )
  736. SCM_obj ptr;
  737. { return SCM_int_to_obj( (long)*((long *)SCM_obj_to_int(ptr)) ); }
  738.  
  739. SCM_obj mac_X23poke32( ptr, val )
  740. SCM_obj ptr, val;
  741. { *((long *)SCM_obj_to_int(ptr)) = (long)SCM_obj_to_int(val);
  742.   return (long)SCM_false;
  743. }
  744.  
  745. extern int edit( /* name, line, chr */ );
  746.  
  747. SCM_obj mac_X23edit( name, line, chr)
  748. SCM_obj name, line, chr;
  749. { SCM_obj result;
  750.   GrafPtr save;
  751.   char pname[FILENAME_LEN];
  752.   char path[FILENAME_LEN];
  753.   char *p = SCM_obj_to_str(name);
  754.   long len = SCM_length(name);
  755.   int full_path = 0;
  756.  
  757.   if ((len == 0) || (len >= FILENAME_LEN)) return (long)SCM_false;
  758.  
  759.   GetPort( &save );
  760.  
  761.   pname[0] = len;
  762.   path[len] = '\0';
  763.   while (len > 0)
  764.   { char c = p[len-1];
  765.     if (c == ':') full_path = 1;
  766.     pname[len] = c;
  767.     len--;
  768.     path[len] = c;
  769.   }
  770.  
  771.   if ((full_path || getfullpathfromcurrentvolume( pname, path, FILENAME_LEN, 1 )) &&
  772.       edit( path, SCM_obj_to_int(line), SCM_obj_to_int(chr) ))
  773.     result = (long)SCM_true;
  774.   else
  775.     result = (long)SCM_false;
  776.  
  777.   SetPort( save );
  778.  
  779.   return result;
  780. }
  781.  
  782. SCM_obj mac_X23help( str )
  783. SCM_obj str;
  784. { Str255 pstr;
  785.   pascal_str( str, pstr );
  786.   help_find( pstr );
  787.   return (long)SCM_false;
  788. }
  789.  
  790. /*---------------------------------------------------------------------------*/
  791.  
  792.  
  793. void ext_init()
  794. { DEFINE_C_PROC(mac_X23newwindow);
  795.   DEFINE_C_PROC(mac_X23getnewwindow);
  796.   DEFINE_C_PROC(mac_X23disposewindow);
  797.   DEFINE_C_PROC(mac_X23setwtitle);
  798.   DEFINE_C_PROC(mac_X23selectwindow);
  799.   DEFINE_C_PROC(mac_X23hidewindow);
  800.   DEFINE_C_PROC(mac_X23showwindow);
  801.   DEFINE_C_PROC(mac_X23frontwindow);
  802.   DEFINE_C_PROC(mac_X23findwindow);
  803.   DEFINE_C_PROC(mac_X23trackgoaway);
  804.   DEFINE_C_PROC(mac_X23dragwindow);
  805.   DEFINE_C_PROC(mac_X23invalrect);
  806.   DEFINE_C_PROC(mac_X23beginupdate);
  807.   DEFINE_C_PROC(mac_X23endupdate);
  808.  
  809.   DEFINE_C_PROC(mac_X23openport);
  810.   DEFINE_C_PROC(mac_X23initport);
  811.   DEFINE_C_PROC(mac_X23closeport);
  812.   DEFINE_C_PROC(mac_X23setport);
  813.   DEFINE_C_PROC(mac_X23getport);
  814.   DEFINE_C_PROC(mac_X23setorigin);
  815.   DEFINE_C_PROC(mac_X23backpat);
  816.   DEFINE_C_PROC(mac_X23hidecursor);
  817.   DEFINE_C_PROC(mac_X23showcursor);
  818.   DEFINE_C_PROC(mac_X23pensize);
  819.   DEFINE_C_PROC(mac_X23penmode);
  820.   DEFINE_C_PROC(mac_X23penpat);
  821.   DEFINE_C_PROC(mac_X23pennormal);
  822.   DEFINE_C_PROC(mac_X23moveto);
  823.   DEFINE_C_PROC(mac_X23move);
  824.   DEFINE_C_PROC(mac_X23lineto);
  825.   DEFINE_C_PROC(mac_X23line);
  826.   DEFINE_C_PROC(mac_X23textfont);
  827.   DEFINE_C_PROC(mac_X23textface);
  828.   DEFINE_C_PROC(mac_X23textmode);
  829.   DEFINE_C_PROC(mac_X23textsize);
  830.   DEFINE_C_PROC(mac_X23spaceextra);
  831.   DEFINE_C_PROC(mac_X23drawchar);
  832.   DEFINE_C_PROC(mac_X23drawstring);
  833.   DEFINE_C_PROC(mac_X23drawtext);
  834.   DEFINE_C_PROC(mac_X23charwidth);
  835.   DEFINE_C_PROC(mac_X23stringwidth);
  836.   DEFINE_C_PROC(mac_X23textwidth);
  837.   DEFINE_C_PROC(mac_X23localtoglobal);
  838.   DEFINE_C_PROC(mac_X23globaltolocal);
  839.   DEFINE_C_PROC(mac_X23framerect);
  840.   DEFINE_C_PROC(mac_X23paintrect);
  841.   DEFINE_C_PROC(mac_X23eraserect);
  842.   DEFINE_C_PROC(mac_X23invertrect);
  843.   DEFINE_C_PROC(mac_X23fillrect);
  844.   DEFINE_C_PROC(mac_X23frameroundrect);
  845.   DEFINE_C_PROC(mac_X23paintroundrect);
  846.   DEFINE_C_PROC(mac_X23eraseroundrect);
  847.   DEFINE_C_PROC(mac_X23invertroundrect);
  848.   DEFINE_C_PROC(mac_X23fillroundrect);
  849.   DEFINE_C_PROC(mac_X23frameoval);
  850.   DEFINE_C_PROC(mac_X23paintoval);
  851.   DEFINE_C_PROC(mac_X23eraseoval);
  852.   DEFINE_C_PROC(mac_X23invertoval);
  853.   DEFINE_C_PROC(mac_X23filloval);
  854.   DEFINE_C_PROC(mac_X23framearc);
  855.   DEFINE_C_PROC(mac_X23paintarc);
  856.   DEFINE_C_PROC(mac_X23erasearc);
  857.   DEFINE_C_PROC(mac_X23invertarc);
  858.   DEFINE_C_PROC(mac_X23fillarc);
  859.  
  860.   DEFINE_C_PROC(mac_X23newmenu);
  861.   DEFINE_C_PROC(mac_X23getmenu);
  862.   DEFINE_C_PROC(mac_X23disposemenu);
  863.   DEFINE_C_PROC(mac_X23appendmenu);
  864.   DEFINE_C_PROC(mac_X23addresmenu);
  865.   DEFINE_C_PROC(mac_X23insertresmenu);
  866.   DEFINE_C_PROC(mac_X23insertmenu);
  867.   DEFINE_C_PROC(mac_X23drawmenubar);
  868.   DEFINE_C_PROC(mac_X23deletemenu);
  869.   DEFINE_C_PROC(mac_X23clearmenubar);
  870.   DEFINE_C_PROC(mac_X23getnewmbar);
  871.   DEFINE_C_PROC(mac_X23getmenubar);
  872.   DEFINE_C_PROC(mac_X23setmenubar);
  873.   DEFINE_C_PROC(mac_X23menuselect);
  874.   DEFINE_C_PROC(mac_X23menukey);
  875.   DEFINE_C_PROC(mac_X23hilitemenu);
  876.   DEFINE_C_PROC(mac_X23disableitem);
  877.   DEFINE_C_PROC(mac_X23enableitem);
  878.   DEFINE_C_PROC(mac_X23getmhandle);
  879.  
  880.   DEFINE_C_PROC(mac_X23sfgetfile);
  881.   DEFINE_C_PROC(mac_X23sfputfile);
  882.  
  883.   DEFINE_C_PROC(mac_X23getmouse);
  884.   DEFINE_C_PROC(mac_X23button);
  885.   DEFINE_C_PROC(mac_X23tickcount);
  886.   DEFINE_C_PROC(mac_X23delay);
  887.   DEFINE_C_PROC(mac_X23sysbeep);
  888.   DEFINE_C_PROC(mac_X23seteventmask);
  889.  
  890.   DEFINE_C_PROC(mac_X23peek8);
  891.   DEFINE_C_PROC(mac_X23poke8);
  892.   DEFINE_C_PROC(mac_X23peek16);
  893.   DEFINE_C_PROC(mac_X23poke16);
  894.   DEFINE_C_PROC(mac_X23peek32);
  895.   DEFINE_C_PROC(mac_X23poke32);
  896.  
  897.   DEFINE_C_PROC(mac_X23edit);
  898.   DEFINE_C_PROC(mac_X23help);
  899. }
  900.  
  901.  
  902. /*---------------------------------------------------------------------------*/
  903.